<%_
var i18nToLoad = [entityInstance];
for (var idx in fields) {
    if (fields[idx].fieldIsEnum == true) {
        i18nToLoad.push(fields[idx].enumInstance);
    }
}
_%>
<%= entityInstancePlural %>: <%= entityClass %>[];
    currentAccount: any;
    eventSubscriber: Subscription;
    <%_ if (searchEngine === 'elasticsearch') { _%>
    currentSearch: string;
    <%_ } _%>

    constructor(
        <%_ if (enableTranslation) { _%>
        private jhiLanguageService: JhiLanguageService,
        <%_ } _%>
        private <%= entityInstance %>Service: <%= entityClass %>Service,
        private alertService: AlertService,
        <%_ if (fieldsContainBlob) { _%>
        private dataUtils: DataUtils,
        <%_ } _%>
        private eventManager: EventManager,
        <%_ if (searchEngine === 'elasticsearch') { _%>
        private activatedRoute: ActivatedRoute,
        <%_ } _%>
        private principal: Principal
    ) {
        <%_ if (searchEngine === 'elasticsearch') { _%>
        this.currentSearch = activatedRoute.snapshot.params['search'] ? activatedRoute.snapshot.params['search'] : '';
        <%_ } _%>
        <%_ if (enableTranslation) { _%>
        this.jhiLanguageService.setLocations(<%- toArrayString(i18nToLoad) %>);
        <%_ } _%>
    }

    loadAll() {
        <%_ if (searchEngine === 'elasticsearch') { _%>
        if (this.currentSearch) {
            this.<%= entityInstance %>Service.search({
                query: this.currentSearch,
                }).subscribe(
                    (res: Response) => this.<%= entityInstancePlural %> = res.json(),
                    (res: Response) => this.onError(res.json())
                );
            return;
       }
       <%_ } _%>
        this.<%= entityInstance %>Service.query().subscribe(
            (res: Response) => {
                this.<%= entityInstancePlural %> = res.json();
                <%_ if (searchEngine === 'elasticsearch') { _%>
                this.currentSearch = '';
                <%_ } _%>
            },
            (res: Response) => this.onError(res.json())
        );
    }
    <%_ if (searchEngine === 'elasticsearch') { _%>

    search (query) {
        if (!query) {
            return this.clear();
        }
        this.currentSearch = query;
        this.loadAll();
    }

    clear() {
        this.currentSearch = '';
        this.loadAll();
    }
    <%_ } _%>
